<template>
  <page-wrap back hide-tab title="关注企业" class="page" stayStill>
    <view class="company-list">
      <view
        v-for="item in companyList"
        :key="item.company_id"
        class="company-list-item"
        @click="goToCompanyDetail(item)"
      >
        <u-image
          width="140rpx"
          height="85rpx"
          :src="item.logopath"
          border-radius="24"
          class="logo"
        >
        </u-image>
        <view class="list-item_right">
          <text class="company-title">{{ item.cname }}</text>
          <view class="company-detail">
            {{ item.cxz }}
            <text> | </text>
            {{ item.yuangong }}
          </view>
        </view>
      </view>
      <u-loadmore
        class="company-more"
        :status="moreLoading"
        :load-text="loadText"
      />
    </view>
  </page-wrap>
</template>

<script>
import { getConcernCompany } from "@/api/index";
import ShareMixin from '@/mixins/share';
export default {
  mixins: [ShareMixin],
  data() {
    return {
      personId: uni.getStorageSync("person-id").slice(2) || undefined,
      emptyShow: false,
      companyList: [],
      pageParam: {
        page: 0,
        pageSize: 20,
      },
      total: 0,
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "没有更多了",
      },
      sharePath: '/pagesSub/userCenter/concernCompany/index',
    };
  },
  created() {
    this.getConcernCompany();
  },
  onReachBottom() {
    this.$set(this.pageParam, "page", this.pageParam.page + 1);
    this.getConcernCompany();
  },
  // onShareAppMessage() {
  //   return {
  //     title: this.$selfName,
  //     path: "/pages/index/index",
  //   };
  // },
  // onShareTimeline() {
  //   return {
  //     title: this.$selfName,
  //     path: "/pages/index/index",
  //   };
  // },
  methods: {
    getConcernCompany() {
      if (this.moreLoading === "loading" || this.moreLoading === "nomore")
        return;
      this.moreLoading = "loading";
      let param = {
        condition_arr: JSON.stringify({
          get_zw_update: "1",
          follow_type: "1",
          uid: this.personId,
          visitor_pid: this.personId,
          user_role: "20",
          pagesize: this.pageParam.pageSize,
          pageindex: this.pageParam.page,
        }),
      };
      getConcernCompany(param).then((res) => {
        if (res.data && res.data.length) {
          this.total = res.pageparam.sums;
          this.moreLoading = "loadmore";
          this.companyList.push(...res.data);
          if (this.companyList.length >= this.total) {
            this.moreLoading = "nomore";
            return;
          }
        } else {
          this.moreLoading = "nomore";
        }
      });
    },
    goToCompanyDetail(item) {
      uni.navigateTo({
        url:
          "/pagesSub/public/companyDetail/index?companyId=" + item.company_id,
      });
    },
  },
};
</script>

<style lang="scss">
.page {
  .company-list {
    margin: 32rpx 32rpx 24rpx;
    &-item {
      display: flex;
      background-color: $uni-bg-color;
      border-radius: 24rpx;
      margin-bottom: $uni-spacing-col-lg;
      padding: 32rpx;
      .logo {
        margin-right: 24rpx;
      }
      .company-title {
        font-size: $uni-font-size-base;
        color: $uni-text-color-222;
      }
      .company-detail {
        margin-top: 10rpx;
        font-size: $uni-font-size-sm;
        color: $uni-text-color-555;
        text {
          display: inline-block;
          margin: 0 4px;
          vertical-align: 1px;
        }
      }
    }
  }
}
</style>
